﻿<?php
require('configs/include.php');

class c_verificar_programa extends super_controller {

    public function verificar() {
        if (is_empty($this->post->id) || is_empty($this->post->requisito)) {
            throw_exception("Debe seleccionar un Programa y un Estado de requisito");
        } else {
            $programa = new programa();
            $programa->set('id', $this->post->id);
            $programa->set('estado_requisito', $this->post->requisito);
            $this->orm->connect();
            $this->orm->update_data("by_estado_requisito", $programa);
            $programador = new programador();
            $programador->set('usuario', $this->post->programador);
            $programador->set('reputacion', $this->post->reputacion);
            //Se actualiza la reputación del programador
            $this->orm->update_data("by_id_reputacion", $programador);
            $this->orm->close();
            $this->type_warning = "success";
            $this->msg_warning = "Programa verificado correctamente";
            $this->img_warning = "correct.png";
            $this->engine->assign('img_warning', $this->img_warning);
            $this->temp_aux = 'message.tpl';
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
        }
    }

public function display() {
    $options['programa']['lvl2'] = "by_estado_null";
    $this->orm->connect();
    $this->orm->read_data(array("programa"), $options);
    $programas = $this->orm->get_objects("programa");
    $this->orm->close();
    $this->engine->assign('programas', $programas);
    $varAux = $this->gvar['n_index'] . " -> " . $this->gvar['n_program'];
    $this->engine->assign('ubicationPath', $varAux);
    $this->engine->display('header.tpl');
    $this->engine->display('verificar_programa.tpl');
    $this->engine->display($this->temp_aux);
    $this->engine->display('footer.tpl');
    }

    public

    function run() {
        if ($_SESSION['usuario']['tipo'] == "intermediario") {
            try {
                if (isset($this->get->option)) {
                    $this->{$this->get->option}();
                }
            } catch (Exception $e) {
                $this->error = 1;
                $this->msg_warning = $e->getMessage();
                $this->img_warning = "incorrect.png";
                $this->engine->assign('type_warning', $this->type_warning);
                $this->engine->assign('msg_warning', $this->msg_warning);
                $this->engine->assign('img_warning', $this->img_warning);
                $this->temp_aux = 'message.tpl';
            }
            $this->display();
        } else {
            $this->engine->display('header.tpl');
            $this->engine->display('sinPermisos.tpl');
            $this->engine->display('footer.tpl');
        }
    }

}



$call = new c_verificar_programa();
$call->run();
?>